﻿using System;
using System.IO;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace time
{
    [TestFixture]
    internal class msdn1
    {
        [Test]
        public void t1()
        {
            Selenium.ISelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://msdn.microsoft.com/en-us/library/");

            //Type type1 = typeof(Console);
            Type type1 = typeof(System.Text.StringBuilder);
            search(selenium, type1);

            while (type1.BaseType.ToString().ToLower().IndexOf("object") == -1)
            {
                search(selenium, type1.BaseType);
            }
        }

        [Test]
        public void t2()
        {
            Selenium.ISelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://msdn.microsoft.com/en-us/library/");

            //Type type1 = typeof(Console);
            //Type type1 = typeof(System.Text.StringBuilder);

            string file = "class.txt";
            StreamReader sr = new StreamReader(file);

            while (!sr.EndOfStream)
            {
                string s = sr.ReadLine().Trim();
                if (s.Trim() != "")
                {
                    showType(selenium, s);
                }
            }

            sr.Close();
        }

        private static void showType(Selenium.ISelenium selenium, string strType)
        {
            Type type1 = null;
            type1 = System.Type.GetType(strType);

            if (type1 != null)
            {
                search(selenium, type1);

                while (type1.BaseType.ToString().ToLower().IndexOf("object") == -1)
                {
                    type1 = type1.BaseType;
                    search(selenium, type1.BaseType);
                }
            }
        }

        private static void search(Selenium.ISelenium selenium, Type type1)
        {
            selenium.Start();
            selenium.Open(@"http://msdn.microsoft.com/en-us/library/");
            selenium.WindowMaximize();
            Thread.Sleep(1000);

            //selenium.WaitForPageToLoad("30000");
            selenium.Type("id=SearchInput", type1.ToString());
            selenium.Click("css=input[type=\"image\"]");
            Thread.Sleep(30000);

            selenium.Close();
        }
    }
}